<!-- 教师个人中心 -->

<template>
  <div>
    <el-card style="width: 60%;margin: 50px auto;">
      <p style="text-align: center;font-size: 25px">个人信息</p>
      <hr style="margin-bottom: 50px;">
      <div style="width: 50%;margin:0 auto">
        <el-form label-position="left" label-width="90px" :model="form">
          <el-form-item label="用户名：">
            <span>{{ form.username }}</span>
            <span style="float: right">注册时间: <span style="color: #ff0000">{{
                dateFormat(form.createTime)
              }}</span></span>
          </el-form-item>
          <el-form-item label="昵称：">
            <el-input :disabled="isDisabled" v-model="form.nickname" clearable></el-input>
          </el-form-item>
          <el-form-item label="邮箱：">
            <el-input :disabled="isDisabled" v-model="form.email" clearable></el-input>
          </el-form-item>
          <el-form-item label="电话：">
            <el-input :disabled="isDisabled" v-model="form.phone" clearable></el-input>
          </el-form-item>
          <el-form-item label="地址：">
            <el-input :disabled="isDisabled" v-model="form.address" clearable></el-input>
          </el-form-item>
          <el-form-item label="个性签名：">
            <el-input
                v-model="form.strSign"
                type="textarea"
                autosize
                placeholder="这个人很懒，什么也没有留下......"
                :disabled="isDisabled">
            </el-input>
          </el-form-item>
        </el-form>
      </div>

      <div style="text-align: center">
        <el-button @click="edit" type="success" :disabled="Btn1_isDisabled">编辑</el-button>
        <el-button @click="Ok" type="primary" :disabled="Btn2_isDisabled">确定</el-button>
      </div>

    </el-card>
  </div>
</template>

<script>
export default {
  name: "Tea_PersonalCenter",
  data() {
    return {
      isDisabled: true,
      Btn1_isDisabled: false,
      Btn2_isDisabled: true,
      form: {},
      Teacher: localStorage.getItem("Teacher") ? JSON.parse(localStorage.getItem("Teacher")) : {}
    }
  },
  created() {
    this.request.get("/teacher/teacherName/" + this.Teacher.username).then(res => {
      if (res.code === "code_200") {
        this.form = res.data
      }
    })
  },
  methods: {
    edit() {
      this.isDisabled = !this.isDisabled
      this.Btn1_isDisabled = true
      this.Btn2_isDisabled = false
    },
    Ok() {
      this.request.post("/teacher/upDataInfo" , this.form).then(res => {
        if (res.code === "code_200") {
          this.$message.success("编辑成功！")
          this.location.reload()
        } else {
          this.$message.error("编辑失败！")
        }
      })
      this.isDisabled = !this.isDisabled
      this.Btn1_isDisabled = false
      this.Btn2_isDisabled = true
    },
    dateFormat: function (time) {
      // 格式化日期
      let date = new Date(new Date(time).getTime());
      let year = date.getFullYear();
      let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
      let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      // 拼接
      return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
    }
  }
}
</script>

<style scoped>

</style>